1. 题目描述(简单难度)

[warning] 145. 二叉树的后序遍历

2. 解法一:DFS

class Solution {
    List<Integer> resp = new ArrayList<>();
    public List<Integer> postorderTraversal(TreeNode root) {
       if(null == root){
           return new ArrayList<>();
       }
       dfs(root);
       return resp;
    }

    public void dfs(TreeNode root){
        if(root == null){
            return;
        }
        dfs(root.left);
        dfs(root.right);
        resp.add(root.val);
    }
}
© gaohueric all right reserved,powered by Gitbook文件修订时间: 2021-12-08 23:22:22

results matching ""

    No results matching ""